<%@ page import="com.zhongkun.pojo.Picture" %>
<%@ page import="com.zhongkun.pojo.UserShare" %>
<%@ page import="com.zhongkun.pojo.User" %>
<%@ page import="com.zhongkun.pojo.Comment" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.stream.Collectors" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html class="no-js" lang="en">

<%
    User user = (User)request.getSession().getAttribute("userLogin");
%>

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>欢迎<%= user.getNikename() %></title>
    <meta name="robots" content="noindex, follow" />
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- Favicon -->
    <link rel="shortcut icon" type="image/x-icon" href="${pageContext.request.contextPath}/assets/images/favicon.ico">

    <!-- CSS
	============================================ -->
    <!-- google fonts -->
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i,900" rel="stylesheet">
    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/vendor/bootstrap.min.css">
    <!-- Icon Font CSS -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/vendor/bicon.min.css">
    <!-- Flat Icon CSS -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/vendor/flaticon.css">
    <!-- audio & video player CSS -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/plugins/plyr.css">
    <!-- Slick CSS -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/plugins/slick.min.css">
    <!-- nice-select CSS -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/plugins/nice-select.css">
    <!-- perfect scrollbar css -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/plugins/perfect-scrollbar.css">
    <!-- light gallery css -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/plugins/lightgallery.min.css">
    <!-- Main Style CSS -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/style.css">

</head>

//写几个全局方法吧
<%!
    String findSharePic(int id,List<Picture> picture){
        List<Picture> pic = picture.stream().filter(p->p.getId() == id).collect(Collectors.toList());
        if (pic.size() != 1){
            System.out.println("这图有问题啊");
            return "错误";
        }
        return pic.get(0).getPath();
    }

    User findShareUser(int id,List<User> users){
        List<User> user = users.stream().filter(u->u.getId() == id).collect(Collectors.toList());
        if (user.size() != 1){
            System.out.println("这用户有问题啊");
            return null;
        }
        return user.get(0);
    }

    String findShareProfile(int id,List<User> users,List<Picture> picture){
        List<User> user = users.stream().filter(u->u.getId() == id).collect(Collectors.toList());
        if (user.size() != 1){
            System.out.println("这头像有问题啊");
            return "错误";
        }
        return findSharePic(user.get(0).getProfile(),picture);
    }

    List<Comment> findShareComment(int id,List<Comment> commentList){
        List<Comment> comments = commentList.stream().filter(c->c.getUser_id() == id).collect(Collectors.toList());
        if (comments.size() == 0 || comments == null){
            System.out.println("没评论啊");
            return null;
        }
        return comments;
    }

    //生成随机九个序号 为pictureList 随机挑选九个id
    String[] getNinePictureByRandom(List<Picture> pictureList){
        List<Picture> picture =  new ArrayList<>();
        picture.addAll(pictureList);
        int maxId = picture.size();
        int theId = 0;
        int i = 0;
        String [] ninePicPath = new String[9];
        while (i < 9){
            theId = (int)(Math.random()*maxId);
            if(picture.isEmpty()) {
                i++;
                continue;
            }else if (i > maxId && maxId == 0){
                break;
            }
            ninePicPath[i] = picture.get(theId).getPath();
            picture.remove(theId);
            i++;
            maxId--;
        }
        return ninePicPath;
    }

%>

<%
    Picture pic = (Picture) request.getSession().getAttribute("profilePath");
    List<Picture> pictureList = (List<Picture>) request.getSession().getAttribute("allPicture");
    List<UserShare> userShareTime = (List<UserShare>) request.getSession().getAttribute("share");
    List<UserShare> userShareHot = (List<UserShare>) request.getSession().getAttribute("shareHot");
    List<User> users = (List<User>) request.getSession().getAttribute("allUserByTime");
    List <Comment> commentList= (List<Comment>) request.getSession().getAttribute("allComment");
%>

<body>

<!-- header area start -->
<header>
    <div class="header-top sticky bg-white d-none d-lg-block">
        <div class="container">
            <div class="row align-items-center">
                <div class="col-md-5">
                    <!-- header top navigation start -->
                    <div class="header-top-navigation">
                        <nav>
                            <ul>
                                <li class="active"><a href="index.html">首页</a></li>
                                <li class="msg-trigger"><a class="msg-trigger-btn" href="#a">个人主页</a>

                                </li>
                                <li class="notification-trigger"><a class="msg-trigger-btn" href="#b">#待添加</a>

                                </li>
                            </ul>
                        </nav>
                    </div>
                    <!-- header top navigation start -->
                </div>

                <div class="col-md-2">
                    <!-- brand logo start -->
                    <div class="brand-logo text-center">
                        <a href="index.html">
                            <img src="${pageContext.request.contextPath}/assets/images/logo/logo.png" alt="brand logo">
                        </a>
                    </div>
                    <!-- brand logo end -->
                </div>

                <div class="col-md-5">
                    <div class="header-top-right d-flex align-items-center justify-content-end">
                        <!-- header top search start -->
                        <div class="header-top-search">
                            <form class="top-search-box">
                                <input type="text" placeholder="Search" class="top-search-field">
                                <button class="top-search-btn"><i class="flaticon-search"></i></button>
                            </form>
                        </div>
                        <!-- header top search end -->

                        <!-- profile picture start -->
                        <div class="profile-setting-box">
                            <div class="profile-thumb-small">
                                <a href="javascript:void(0)" class="profile-triger">
                                    <figure>
                                        <img src="<%= pic.getPath()%>" alt="profile picture">
                                    </figure>
                                </a>
                                <div class="profile-dropdown">
                                    <div class="profile-head">
                                        <h5 class="name"><a href="#"><%= user.getNikename()%></a></h5>
                                        <a class="mail" href="#"><%= user.getUsername()%></a>
                                    </div>
                                    <div class="profile-body">
                                        <ul>
                                            <li><a href="profile.html"><i class="flaticon-user"></i>个人中心</a></li>
                                            <li><a href="#"><i class="flaticon-message"></i>#待添加</a></li>
                                            <li><a href="#"><i class="flaticon-document"></i>动态</a></li>
                                        </ul>
                                        <ul>
                                            <li><a href="signup.html"><i class="flaticon-unlock"></i>登出</a></li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</header>
<!-- header area end -->
<!-- header area start -->
<header>
    <div class="mobile-header-wrapper sticky d-block d-lg-none">
        <div class="mobile-header position-relative ">
            <div class="mobile-logo">
                <a href="index.html">
                    <img src="assets/images/logo/logo-white.png" alt="logo">
                </a>
            </div>
            <div class="mobile-menu w-100">
                <ul>
                    <li style="margin-left: 10%;">
                        <h3>欢迎来耍yo~</h3>
                    </li>
                    <li>
                        <button class="search-trigger">
                            <i class="search-icon flaticon-search"></i>
                            <i class="close-icon flaticon-cross-out"></i>
                        </button>
                        <div class="mob-search-box">
                            <form class="mob-search-inner">
                                <input type="text" placeholder="Search Here" class="mob-search-field">
                                <button class="mob-search-btn"><i class="flaticon-search"></i></button>
                            </form>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="mobile-header-profile">
                <!-- profile picture end -->
                <div class="profile-thumb profile-setting-box">
                    <a href="javascript:void(0)" class="profile-triger">
                        <figure class="profile-thumb-middle">
                            <img src="assets/images/profile/profile-small-1.jpg" alt="profile picture">
                        </figure>
                    </a>
                    <div class="profile-dropdown text-left">
                        <div class="profile-head">
                            <h5 class="name"><a href="#">昵称</a></h5>
                            <a class="mail" href="#">用户名</a>
                        </div>
                        <div class="profile-body">
                            <ul>
                                <li><a href="profile.html"><i class="flaticon-user"></i>个人主页</a></li>
                                <li><a href="#"><i class="flaticon-message"></i>#待定</a></li>
                                <li><a href="#"><i class="flaticon-document"></i>动态</a></li>
                            </ul>
                            <ul>
                                <li><a href="signup.html"><i class="flaticon-unlock"></i>Sing out</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <!-- profile picture end -->
            </div>
        </div>
    </div>
</header>
<!-- header area end -->



<main>

    <div class="main-wrapper">
        <div class="profile-banner-large bg-img" data-bg="<%= pictureList.get(4).getPath()%>">
        </div>
        <div class="profile-menu-area bg-white">
            <div class="container">
                <div class="row align-items-center">
                    <div class="col-lg-3 col-md-3">
                        <div class="profile-picture-box">
                            <figure class="profile-picture">
                                <a href="profile.html">
                                    <img src="<%= pic.getPath() %>" alt="profile picture">
                                </a>
                            </figure>
                        </div>`
                    </div>
                    <div class="col-lg-6 col-md-6 offset-lg-1">
                        <div class="profile-menu-wrapper">
                            <div class="main-menu-inner header-top-navigation">
                                <nav>
                                    <ul class="main-menu">
                                        <li class="active"><a href="#">时间串</a></li>
                                        <li><a href="about.html">关于</a></li>
                                        <li><a href="photos.html">本站图库</a></li>
                                        <li><a href="friends.html">所有同学</a></li>
                                        <li><a href="about.html">更多</a></li>
                                        <!-- <li class="d-inline-block d-md-none"><a href="profile.html">edit profile</a></li> -->
                                    </ul>
                                </nav>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-2 col-md-3 d-none d-md-block">
                        <div class="profile-edit-panel">
                            <button class="edit-btn">改头换面啦</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="container">
            <div class="row">
                <div class="col-lg-3 order-2 order-lg-1">
                    <aside class="widget-area profile-sidebar">
                        <!-- widget single item start -->
                        <div class="card widget-item">
                            <h4 class="widget-title">站长公告</h4>
                            <div class="widget-body">
                                <div class="about-author">
                                    <p>欢迎且感谢来到我的网站玩耍，水平有限bug可能会有点多，反馈即可，不过反馈了也不一定解决</p>
                                </div>
                            </div>
                        </div>
                        <!-- widget single item end -->

                        <!-- widget single item start -->
                        <div class="card widget-item">
                            <h4 class="widget-title">推荐图片</h4>
                            <div class="widget-body">
                                <div class="sweet-galley img-gallery">
                                    <div class="row row-5">
                                        <%
                                            String [] ninePicPath = new String[9];
                                            ninePicPath = getNinePictureByRandom(pictureList);
                                            //System.out.println(picNine);
                                            for(int i = 0;i < 9;i++){
                                                if (ninePicPath[i] == null){
                                                    continue;
                                                }
                                        %>
                                        <div class="col-4">
                                            <div class="gallery-tem">
                                                <figure class="post-thumb">
                                                    <a class="gallery-selector" href="<%= ninePicPath[i] %>">
                                                        <img src="<%= ninePicPath[i] %>" alt="sweet memory">
                                                    </a>
                                                </figure>
                                            </div>
                                        </div>
                                       <%
                                           }
                                       %>



                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- widget single item end -->

                        <!-- widget single item start -->

                        <!-- widget single item end -->
                    </aside>
                </div>

                <div class="col-lg-6 order-1 order-lg-2">
                    <!-- share box start -->
                    <div class="card card-small">
                        <div class="share-box-inner">
                            <!-- profile picture end -->
                            <div class="profile-thumb">
                                <a href="#">
                                    <figure class="profile-thumb-middle">
                                        <img src="<%= pic.getPath() %>" alt="profile picture">
                                    </figure>
                                </a>
                            </div>
                            <!-- profile picture end -->

                            <!-- share content box start -->
                            <div class="share-content-box w-100">
                                <form class="share-text-box">
                                    <textarea name="share" class="share-text-field" aria-disabled="true" placeholder="写点啥呢……" data-toggle="modal" data-target="#textbox" id="email"></textarea>
                                    <button class="btn-share" type="submit">发布动态</button>
                                </form>
                            </div>
                            <!-- share content box end -->
                            <!-- Modal start -->
                            <div class="modal fade" id="textbox" aria-labelledby="textbox">
                                <div class="modal-dialog">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h5 class="modal-title">你想写点啥？</h5>
                                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                <span aria-hidden="true">&times;</span>
                                            </button>
                                        </div>
                                        <div class="modal-body custom-scroll">
                                            <textarea name="share" class="share-field-big custom-scroll" placeholder="写点啥呢……" maxlength="250"></textarea>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="post-share-btn" data-dismiss="modal">不想发啦</button>
                                            <button type="button" class="post-share-btn">发布</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- Modal end -->
                        </div>
                    </div>
                    <!-- share box end -->

                    <!-- post status start -->
                    <%
                        int i = 0;
                        while(i<userShareTime.size()){
                            List<Comment> comments = new ArrayList<>();
                            if(findShareComment(userShareTime.get(i).getId(),commentList) != null){
                                comments.addAll(findShareComment(userShareTime.get(i).getId(),commentList));
                            }
                    %>
                    <!-- post status start -->
                    <div class="card">
                        <!-- post title start -->
                        <div class="post-title d-flex align-items-center">
                            <!-- profile picture end -->
                            <div class="profile-thumb">
                                <a href="#">
                                    <figure class="profile-thumb-middle">
                                        <img src="<%=findShareProfile(userShareTime.get(i).getUser_id(),users,pictureList)%>" alt="profile picture">
                                    </figure>
                                </a>
                            </div>
                            <!-- profile picture end -->

                            <div class="posted-author">
                                <h6 class="author"><a href="profile.html"><%= findShareUser(userShareTime.get(0).getUser_id(),users).getNikename()%></a></h6>
                                <span class="post-time"><%= userShareTime.get(i).getTime() %></span>
                            </div>

                        </div>
                        <!-- post title start -->
                        <div class="post-content">
                            <p class="post-desc">
                                <%= userShareTime.get(i).getContent() %>
                            </p>
                            <div class="post-thumb-gallery">
                                <figure class="post-thumb img-popup">
                            <%
                                int pid = 0;
                                if (pid + userShareTime.get(i).getPic_id() != 0){
                            %>
                                    <a href="<%= findSharePic(userShareTime.get(i).getPic_id(),pictureList) %>">
                                        <img src="<%= findSharePic(userShareTime.get(i).getPic_id(),pictureList) %>" alt="post image">
                                    </a>
                            <%
                                }
                            %>
                                </figure>
                            </div>
                            <div class="post-meta">
                                <button class="post-meta-like">
                                    <i class="bi bi-heart-beat"></i>
                                    <span>有<%= userShareTime.get(i).getLike() %>个憨憨和你一起表示了喜欢</span>
                                    <strong><%= userShareTime.get(i).getLike() %></strong>
                                </button>
                                <ul class="comment-share-meta">
                                    <li>
                                        <button class="btn post-comment" type="button" data-toggle="collapse" data-target="#collapseExample<%=i%>" aria-expanded="false" aria-controls="collapseExample">
                                            <i class="bi bi-chat-bubble"></i>
                                            <span><%= comments.size() %></span>
                                        </button>
                                    </li>
                                </ul>
                            </div>
                        </div>

                        <!-- 打算评论区 -->
                        <div id="collapseExample<%=i%>" class="widget-body collapse"  style="margin-top: 1.25rem;" >
                            <h4 class="widget-title">评论区</h4>
                            <%--输入框--%>
                            <div class="share-content-box w-100" style="margin-top: -20px;">
                                <form class="share-text-box">
											<textarea name="share" class="share-text-field" aria-disabled="true" placeholder="评论点啥呢……"></textarea>
                                    <button class="btn-share" type="submit">发布评论</button>
                                </form>
                            </div>
                            <ul class="like-page-list-wrapper">
                                <%
                                    while (!comments.isEmpty()){
                                %>
                                <li class="unorder-list">
                                    <!-- profile picture end -->
                                    <div class="profile-thumb">
                                        <a href="#">
                                            <figure class="profile-thumb-small">
                                                <img src="<%= findShareProfile(comments.get(0).getUser_id(),users,pictureList) %>" alt="profile picture">
                                            </figure>
                                        </a>
                                    </div>
                                    <!-- profile picture end -->

                                    <div class="unorder-list-info">
                                        <h3 class="list-title" style="font-weight: bold;"><a href="#"><%= findShareUser(comments.get(0).getUser_id(),users).getNikename() %></a>
                                        </h3>
                                        <p class="list-subtitle"><%= comments.get(0).getTime()%></p>
                                        <p class="post-desc pb-0"><%= comments.get(0).getContent()%></p>
                                    </div>
                                    <div class=" dropdown-divider"/>
                                </li>
                                <%
                                        comments.remove(0);
                                    }
                                %>
                            </ul>
                        </div>

                    </div>
                    <!-- post status end -->
                    <%
                            i++;
                        }
                    %>
                </div>

                <div class="col-lg-3 order-3">
                    <aside class="widget-area">
                        <!-- widget single item start -->
                        <div class="card widget-item">
                            <h4 class="widget-title">最近加入的同学~</h4>
                            <div class="widget-body">
                                <ul class="like-page-list-wrapper">
                                    <%
                                        List<User> minUserList = new ArrayList<>();
                                        minUserList.addAll(users);
                                        int j = 0;
                                        while(!minUserList.isEmpty()){
                                    %>
                                    <li class="unorder-list">
                                        <!-- profile picture end -->
                                        <div class="profile-thumb">
                                            <a href="#">
                                                <figure class="profile-thumb-small">
                                                    <img src="<%= findShareProfile(minUserList.get(j).getProfile(),users,pictureList)%>" alt="profile picture">
                                                </figure>
                                            </a>
                                        </div>
                                        <!-- profile picture end -->

                                        <div class="unorder-list-info">
                                            <h3 class="list-title"><a href="#"><%= minUserList.get(j).getNikename() %></a></h3>
                                            <p class="list-subtitle"><%= minUserList.get(j).getInformation()%></p>
                                        </div>
                                    </li>
                                    <%
                                            minUserList.remove(j);
                                            j++;
                                        }
                                    %>

                                </ul>
                            </div>
                        </div>
                        <!-- widget single item end -->

                        <!-- widget single item start -->
                        <div class="card widget-item">
                            <h4 class="widget-title">公告招租</h4>
                            <div class="widget-body">
                                <div class="add-thumb">
                                    <a href="#">
                                        <img src="${pageContext.request.contextPath}/assets/images/banner/advertise.jpg" alt="advertisement">
                                    </a>
                                </div>
                            </div>
                        </div>
                        <!-- widget single item end -->

                        <!-- widget single item start -->

                        <!-- widget single item end -->
                    </aside>
                </div>
            </div>
        </div>
    </div>

</main>

<!-- Scroll to top start -->
<div class="scroll-top not-visible">
    <i class="bi bi-finger-index"></i>
</div>
<!-- Scroll to Top End -->

<!-- footer area start -->
<footer class="footer">
    <div class="container">
        <p style="text-align: center;">所有者：钟琨</p>
        <p style="text-align: center;">3274065222@qq.com</p>
    </div>
</footer>
<!-- footer area end -->
<!-- footer area start -->
<footer class="d-block d-lg-none">

</footer>
<!-- footer area end -->

<!-- JS
============================================ -->

<!-- Modernizer JS -->
<script src="${pageContext.request.contextPath}/assets/js/vendor/modernizr-3.6.0.min.js"></script>
<!-- jQuery JS -->
<script src="${pageContext.request.contextPath}/assets/js/vendor/jquery-3.3.1.min.js"></script>
<!-- Popper JS -->
<script src="${pageContext.request.contextPath}/assets/js/vendor/popper.min.js"></script>
<!-- Bootstrap JS -->
<script src="${pageContext.request.contextPath}/assets/js/vendor/bootstrap.min.js"></script>
<!-- Slick Slider JS -->
<script src="${pageContext.request.contextPath}/assets/js/plugins/slick.min.js"></script>
<!-- nice select JS -->
<script src="${pageContext.request.contextPath}/assets/js/plugins/nice-select.min.js"></script>
<!-- audio video player JS -->
<script src="${pageContext.request.contextPath}/assets/js/plugins/plyr.min.js"></script>
<!-- perfect scrollbar js -->
<script src="${pageContext.request.contextPath}/assets/js/plugins/perfect-scrollbar.min.js"></script>
<!-- light gallery js -->
<script src="${pageContext.request.contextPath}/assets/js/plugins/lightgallery-all.min.js"></script>
<!-- image loaded js -->
<script src="${pageContext.request.contextPath}/assets/js/plugins/imagesloaded.pkgd.min.js"></script>
<!-- isotope filter js -->
<script src="${pageContext.request.contextPath}/assets/js/plugins/isotope.pkgd.min.js"></script>
<!-- Main JS -->
<script src="${pageContext.request.contextPath}/assets/js/main.js"></script>

</body>

</html>